<template>
  <div class="newVs">
    <div class="mask"></div>
    <div class="new_vs">
      <div class="vs-top">
        <p>{{ title }}资料（店铺销售）</p>
        <i class="el-icon-close" @click="closeNewClerk"></i>
      </div>
      <div class="vs-info">
        <div class="info">
          <p>销售日期</p>
          <el-date-picker
            v-model="sellTime"
            :disabled="Dis4"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
          <p>VIP</p>
          <el-select
            filterable
            class="wd"
            :disabled="Dis4"
            v-model="vip"
            placeholder="请选择"
            @change="changevip"
          >
            <el-option
              v-for="item in vipList"
              :key="item.value + Math.random()"
              :label="item.label + '  ' + item.value1"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <p>主推</p>
          <el-select v-model="main" :disabled="Dis4">
            <el-option
              v-for="item in clerkList2"
              :key="item.value + Math.random()"
              :label="item.label"
              :value="item.value"
            >
              <span style="float: left">{{ item.value }}</span>
              <span style="float: right">{{ item.value1 }}</span>
            </el-option>
          </el-select>
          <p>次推</p>
          <el-select v-model="minor" :disabled="Dis4">
            <el-option
              v-for="item in clerkList1"
              :key="item.value + Math.random()"
              :label="item.label"
              :value="item.value"
            >
              <span style="float: left">{{ item.value }}</span>
              <span style="float: right">{{ item.value1 }}</span>
            </el-option>
          </el-select>
        </div>
        <div class="info">
          <p>销售序号</p>
          <el-input v-model="vipSellSequence" disabled></el-input>
          <p>折数</p>
          <el-input v-model="discount" :disabled="isPaidOnePrice1"></el-input>
          <p>实收单价</p>
          <el-checkbox
            v-model="isPaidOnePrice"
            :disabled="isPaidOnePrice3"
            border
          ></el-checkbox>
          <el-input
            v-model="onePrice"
            style="width: 113px; margin-left: 10px"
            :disabled="isPaidOnePrice2"
          ></el-input>
          <p>应收</p>
          <el-input v-model="receivable" disabled></el-input>
        </div>
        <div class="info">
          <p>抹零</p>
          <el-input
            class="top-inp"
            v-model="preferential"
            :disabled="Dis"
            @blur="leave"
          ></el-input>
          <p>兑换</p>
          <el-input class="top-inp" v-model="exchange" @input="inp3"></el-input>
          <p>收现</p>
          <el-input class="top-inp" v-model="payg" @input="inp4"></el-input>
          <p>转账</p>
          <el-input class="top-inp" v-model="BigDecimal" disabled></el-input>
        </div>
        <div class="info">
          <p>账户余额</p>
          <el-input class="top-inp" v-model="balance" disabled></el-input>
          <p>账户可兑换额</p>
          <el-input class="top-inp" v-model="canExchange" disabled></el-input>
          <p>备注</p>
          <el-input class="top-inp" v-model="remark"></el-input>
          <p>确认</p>
          <el-input class="top-inp" disabled v-model="isAffirm"></el-input>
        </div>

        <!-- <el-table border :data="codeData" class="tb-edit" style="width: 100%;margin-bottom:15px" max-height="148px" @cell-click="cellClick" :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" :cell-style="{padding:0,height:'36px'}">
          <el-table-column :label="header" width="150"></el-table-column>
          <el-table-column prop="colorName" label="颜色" width="100"></el-table-column>
          <template v-for="i in sizeList">
            <el-table-column :prop="i" :label="i" :key="i+Math.random()">
              <template slot-scope="scope">
                <el-input size="small" v-model="scope.row[i]" @blur="handleInputBlurResult($event,{index:scope.$index,key:i+Math.random(),result:scope.row[i]})" @keyup.enter.native="inpEnter"></el-input>
                <span>{{scope.row[i]}}</span></template>
            </el-table-column>
          </template>
        </el-table> -->
        <el-table
          border
          :data="codeData"
          id="codeTable"
          style="width: 100%; margin-bottom: 20px"
          max-height="148px"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '36px' }"
        >
          <el-table-column :label="header"> </el-table-column>
          <el-table-column prop="colorName" label="颜色"> </el-table-column>
          <template v-for="col in sizeList">
            <el-table-column
              :key="col + Math.random()"
              :prop="col"
              :label="col"
            >
              <template slot-scope="scope">
                <el-input
                  size="small"
                  class="innerInp"
                  v-model="scope.row[col]"
                  @blur="
                    handleClick($event, {
                      index: scope.$index,
                      key: col,
                      result: scope.row[col]
                    })
                  "
                  @keyup.enter.native="inpEnter"
                >
                </el-input>
              </template>
            </el-table-column>
          </template>
        </el-table>

        <div class="barcode">
          <p>条码扫描</p>
          <el-switch
            v-model="isBarcode"
            active-color="#409EFF"
            inactive-color="#C0C4CC"
          ></el-switch>
        </div>

        <div class="enterBarcode">
          <el-input
            id="input"
            ref="barcodeInput"
            v-model="barcode"
            placeholder="扫描/输入货号或款号，输完按回车"
            @keyup.enter.native="barcodeEnter($event)"
          ></el-input>
          <p style="margin: 15px 0 0 5px">合计：{{ howMany }}</p>
        </div>

        <el-table
          height="210px"
          :data="barcodeData"
          style="width: 100%"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '36px' }"
          @row-click="rowClick"
        >
          <el-table-column
            prop="kindsNumber"
            label="款号"
            width="130"
          ></el-table-column>
          <el-table-column prop="colorName" label="颜色"></el-table-column>
          <el-table-column prop="size" label="尺码编号"></el-table-column>

          <el-table-column
            prop="number"
            label="数量"
            width="80"
            show-overflow-tooltip
          >
            <!-- <template slot-scope="scope">
              <el-input class="tabinp" v-model="scope.row.number" @input="inp2"></el-input>
            </template> -->
          </el-table-column>

          <el-table-column
            prop="sellPrice"
            label="售价"
            width="80"
          ></el-table-column>
          <el-table-column
            prop="discount"
            label="折数"
            width="80"
            v-if="Dis4"
          ></el-table-column>
          <el-table-column
            prop="onePrice"
            label="单价"
            width="80"
            v-if="Dis4"
          ></el-table-column>
          <el-table-column prop="discount" label="折数" width="80" v-if="!Dis4">
            <template slot-scope="scope" v-if="!Dis4">
              <el-input
                class="tabinp"
                v-model="scope.row.discount"
                @input="inp"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="onePrice"
            label="单价"
            width="100"
            v-if="!Dis4"
          >
            <template slot-scope="scope" v-if="!Dis4">
              <el-input
                class="tabinp"
                v-model="scope.row.onePrice"
                @input="inp1"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="money"
            label="金额"
            width="100"
          ></el-table-column>
          <el-table-column
            prop="commodityName"
            label="品名"
            width="70"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="brandedName"
            label="品牌"
            width="70"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="enteringTime"
            label="录入时间"
            width="120"
            show-overflow-tooltip
          ></el-table-column>
        </el-table>
      </div>

      <div class="vs-btn">
        <el-button @click="closeNewClerk">关闭</el-button>
        <el-button @click="saveNew" :disabled="jz">结账</el-button>
        <!-- <el-button @click="saveNew" plain type="primary" :disabled="Dis">保存</el-button> -->
        <el-button @click="Edit" type="primary" :disabled="xg">修改</el-button>
        <el-button icon="el-icon-circle-check" @click="Confirm" :disabled="qr"
          >确认</el-button
        >
        <el-button @click="keepGoing" type="primary" :disabled="lv"
          >继续录入</el-button
        >
      </div>

      <!-- F7弹出框 -->
      <div class="popup" :style="{ display: showPopup }">
        <div class="popup_t">
          <p>输入扫描数量</p>
          <i @click="closePopup" class="el-icon-close"></i>
        </div>
        <div class="popup_c">
          <p>请输入扫描数量</p>
          <p>如果不输入则扫描数量为1</p>
          <input
            type="text"
            class="popup_button"
            v-model="scanNum"
            @keyup.enter="
              () => {
                this.showPopup = 'none'
              }
            "
          />
        </div>

        <div class="popup_b">
          <el-button @click="closePopup">取消</el-button>
          <el-button
            type="primary"
            @click="
              () => {
                this.showPopup = 'none'
              }
            "
            >确定</el-button
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { orderBuild, orderQuery } from '../../../../network/manufacturerOrder'
import { getKindsNumberList } from '../../../../network/artNo'
import { getBarCode } from '../../../../network/manufacturer'
import exportMethods from '../../../../components/mixins/exportMethods'
import today from '../../../../components/mixins/today'
import {
  postShop,
  keepPostShop,
  getVip,
  getmoney,
  putShop,
  CheckOut,
  getClerk1,
  getTime,
  getShop,
  confirm
} from '../../../../network/shop'
import enterUp from '../../../../components/mixins/enterUp'
export default {
  mixins: [today, enterUp],
  created() {
    this.inpList = this.getInput() //input enter移动
    this.sellTime = this.searchDateWithHour()
    //  vip
    getVip({ directSaleNo: this.customerNo }).then((res) => {
      console.log(res.data)
      res.data.data.forEach((e) => {
        this.vipList.push({ value: e.phone, label: e.phone, value1: e.name })
      })
    })
    //主推 次推
    getClerk1({ directSaleNo: this.customerNo }).then((res) => {
      console.log(res.data)
      res.data.data.forEach((e) => {
        this.clerkList2.push({
          value: e.personnelNo,
          label: e.personnelNo,
          value1: e.personnelName
        })
        this.clerkList1.push({
          value: e.personnelNo,
          label: e.personnelNo,
          value1: e.personnelName
        })
      })
    })

    if (this.title != '新建') {
      this.fillData()
      this.clerkListChange()
    }

    this.title1Change()
    this.titleChange()
  },
  props: {
    sendData: {
      type: Object,
      default: {}
    },
    clerkList: {
      type: Array,
      default: []
    },
    title: {
      type: String,
      detault: ''
    },
    title1: {
      type: String,
      detault: ''
    },
    customerNo: String
  },
  data() {
    return {
      Dis1: false,
      jz: true,
      xg: true,
      qr: false,
      lv: false,
      isAffirm: '',
      remark: '',
      isPaidOnePrice1: false,
      isPaidOnePrice2: true,
      isPaidOnePrice3: false,
      List: [],
      inpList: [],
      // exchange1:'',
      canExchange: '',
      customerSellSequence: '',
      vipList: [],
      Dis4: false,
      Dis: true,
      // 条码规律详情
      manufacturerBarCode: {},
      // 品牌公司
      brandedCompany: '',
      // 尺码
      knSize: '',
      knSizeList: [],

      showPopup: 'none',
      sellTime: '',
      main: '',
      vipSellSequence: '',
      minor: '',
      vip: '',
      clerkList2: [],
      clerkList1: [],
      discount: '',
      isPaidOnePrice: false,
      onePrice: '',
      receivable: '',
      preferential: '',
      exchange: '',
      payg: '',
      BigDecimal: '',
      balance: '',

      header: '',
      sizeList: [''],
      codeData: [],
      isBarcode: false,
      barcode: '',

      barcodeData: [],
      barcodeData1: [],
      tmpBarcodeData: [],

      tmpData: {},
      scanNum: 1,
      beforeScanNum: 1,
      howMany: ''
    }
  },
  watch: {
    isAffirm(a, b) {
      if (this.isAffirm == '' || this.isAffirm == '未确认') {
      } else {
      }
    },
    barcode(a, b) {
      if (a) {
        this.barcode = a.toUpperCase().trim()
      }
    },
    title1(a, b) {
      this.title1Change
    },
    title(a, b) {
      this.titleChange()
    },
    isPaidOnePrice(a, b) {
      if (a) {
        this.isPaidOnePrice1 = true
        this.isPaidOnePrice2 = false
        this.discount = ''
      } else {
        this.isPaidOnePrice1 = false
        this.isPaidOnePrice2 = true
        this.onePrice = ''
      }
    },

    clerkList(a, b) {
      if (this.title != '新建') {
        this.clerkListChange()
      }
    }
  },
  methods: {
    fillData() {
      const a = this.sendData
      console.log(a)
      this.List = a
      this.vipSellSequence = a.vipSellSequence
      this.exchange = a.exchange
      this.receivable = a.receivable
      this.sellTime = a.sellTime + ' 00:00:00'
      this.vip = a.vip
      this.main = a.main
      this.remark = a.remark
      this.isAffirm = a.affirm
      this.minor = a.minor
      // this.isPaidOnePrice = a.isPaidOnePrice
      this.preferential = a.preferential
      this.payg = a.payg
      this.BigDecimal = a.BigDecimal
      // this.discount = a.discount
      this.onePrice = a.onePrice
      this.balance = a.balance
      this.canExchange = a.canExchange
      setTimeout(() => {
        if (a.settleAccounts == '未结账') {
          if (this.vip != '') {
            getmoney({ vip: this.vip }).then((res) => {
              console.log(res.data)
              this.balance = res.data.data.balance
              this.canExchange = res.data.data.canExchange
            })
          }
        }
      }, 200)
    },
    title1Change() {
      const a = this.title1
      if (a == '00') {
        this.jz = false
        this.xg = true
        this.Dis4 = true
        this.qr = true
        this.lv = true
      }
      if (a == '11') {
        this.jz = true
        this.xg = false
        this.Dis4 = false
        this.qr = false
        this.lv = true
      }
      if (a == '22') {
        this.jz = true
        this.xg = true
        this.Dis4 = false
        this.qr = false
        this.lv = false
      }
    },
    titleChange() {
      const a = this.title
      if (a == '编辑' && this.vipSellSequence == '') {
        this.closeNewClerk() //双击进编辑 数据未渲染 判断数据是否渲染 未 就关闭页面
      }
      if (
        a == '补单' &&
        (this.vipSellSequence == '' || this.barcodeData == '')
      ) {
        this.closeNewClerk() //补单 数据未渲染 判断数据是否渲染 未 就关闭页面
      }
      if (a == '新建' || a == '补单') {
        this.Dis4 = false
      }

      if (a == '新建' && this.isAffirm == '') {
        this.jz = true
        this.lv = false
        this.xg = true
        this.qr = false
      }
      setTimeout(() => {
        console.log(this.isAffirm)
        if (a == '编辑' && (this.isAffirm == '未确认' || this.isAffirm == '')) {
          this.jz = true
          this.xg = false
          this.Dis4 = false
          this.qr = false
          this.lv = true
        }

        if (a == '编辑' && this.isAffirm == '已确认') {
          this.jz = false
          this.xg = true
          this.Dis4 = true
          this.qr = true
          this.lv = true
        }
        if (a == '编辑' && this.isAffirm == '已确认' && this.jz == true) {
          this.closeNewClerk()
        }
        if (a == '补单') {
          this.qr = false
          this.lv = false
          this.xg = true
          this.Dis4 = false
          this.jz = true
        }
      }, 500)

      if (a == '编辑') {
        // this.Dis4 = true
        // this.isPaidOnePrice = true
        this.isPaidOnePrice1 = true
        this.isPaidOnePrice2 = true
        this.isPaidOnePrice3 = true
      } else {
        this.isPaidOnePrice = false
        this.isPaidOnePrice1 = false
        this.isPaidOnePrice3 = false
      }
      if (a == '编辑' || a == '补单') {
        this.Dis = false
        console.log('编辑,补单', this.List)
        for (let y of [this.List]) {
          this.vipSellSequence = y.vipSellSequence
          this.exchange = y.exchange
          this.receivable = y.receivable
          this.sellTime = y.sellTime + ' 00:00:00'
          this.vip = y.vip
          this.main = y.main
          this.remark = y.remark
          this.isAffirm = y.affirm
          this.minor = y.minor
          this.preferential = y.preferential
          this.payg = y.payg
          this.BigDecimal = y.BigDecimal
          this.onePrice = y.onePrice
          this.balance = y.balance
          this.canExchange = y.canExchange
          setTimeout(() => {
            if (this.vip != '') {
              getmoney({ vip: this.vip }).then((res) => {
                console.log(res.data)
                this.balance = res.data.data.balance
                this.canExchange = res.data.data.canExchange
              })
            }
          }, 500)
        }
      } else {
        this.Dis = true
        this.clean()
        this.sellTime = this.searchDateWithHour()
      }
      if (a == '补单') {
        this.qr = false
        this.lv = false
        this.xg = true
        this.Dis4 = false
        this.jz = true
      }
    },
    clerkListChange() {
      const a = this.clerkList
      this.discount = a[0].discount
      this.barcodeData = a
      this.receivable = a.reduce((prev, next) => {
        //a数组里所有money的和
        return prev + next.money
      }, 0)
    },
    inp3() {
      if (this.exchange != '' || this.exchange != 0) {
        this.payg = 0
      }
      if (this.exchange > this.canExchange) {
        this.$message({ message: '兑换额不可以大于账户可兑换额' })
        this.exchange = 0
        return
      }
    },
    inp4() {
      if (this.payg != '' || this.payg != 0) {
        this.exchange = 0
      }
    },
    //确认
    Confirm() {
      if (this.vipSellSequence == '') {
        this.$message.warning({ message: '销售序号为空', offset: 400 })
        return
      }
      confirm({ vipSellSequence: this.vipSellSequence }).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$message.success({ message: '确认成功', offset: 400 })
          this.isAffirm = '已确认'
          this.lv = true
          this.qr = true
          this.jz = false
          this.xg = true
          this.Dis4 = true
          this.$emit('determine')
        }
      })
    },
    Edit() {
      for (let c in this.barcodeData) {
        ;(this.barcodeData[c].sellTime =
          this.sellTime.slice(0, 10) + 'T00:00:00'),
          (this.barcodeData[c].main = this.main),
          (this.barcodeData[c].remark = this.remark),
          (this.barcodeData[c].vip = this.vip),
          (this.barcodeData[c].vipSellSequence = this.vipSellSequence),
          (this.barcodeData[c].minor = this.minor),
          (this.barcodeData[c]['customerSellSequence'] =
            this.customerSellSequence),
          // this.barcodeData[c]['discount'] = this.discount,
          (this.barcodeData[c]['isPaidOnePrice'] =
            this.isPaidOnePrice == false ? 0 : 1),
          // this.barcodeData[c]['onePrice'] = this.onePrice,
          (this.barcodeData[c]['receivable'] = this.receivable), //应收
          (this.barcodeData[c]['preferential'] = this.preferential),
          (this.barcodeData[c]['exchange'] = this.exchange),
          (this.barcodeData[c]['payg'] = this.payg)
        this.barcodeData[c]['BigDecimal'] = this.BigDecimal
      }
      console.log(this.barcodeData)

      console.log(JSON.stringify(this.barcodeData))
      putShop(JSON.stringify(this.barcodeData)).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$emit('closeNew')
          this.$message.success({ message: '修改成功' })
          // if(this.exchange == '' && this.payg == '' && this.BigDecimal == ''){
          //     this.$confirm(`兑换和收现,转账都为空 是否结账, 是否继续?', '提示`, {
          //       confirmButtonText: '确定',
          //       cancelButtonText: '取消',
          //       type: 'warning'
          //     }).then(() => {this.checkOut()});
          //   }else{
          //     this.checkOut()
          //   }
        } else {
          this.$message.error({ message: '修改失败' })
        }
      })
    },

    inp(row, index) {
      for (let a in this.barcodeData) {
        // console.log(this.barcodeData[a].discount)
        this.barcodeData[a].onePrice =
          (Number(this.barcodeData[a].sellPrice) *
            Number(this.barcodeData[a].discount)) /
          10
        this.barcodeData[a].money =
          Number(this.barcodeData[a].onePrice) *
          Number(this.barcodeData[a].number)
        var tst = /^([0-9]|10)$/
        if (
          !tst.test(this.barcodeData[a].discount) &&
          this.barcodeData[a].discount != ''
        ) {
          this.$message.warning({ message: '折数为1-10之间', offset: 400 })
          this.barcodeData[a].discount = 10
          return
        }
      }
      this.receivable = this.barcodeData.reduce((prev, next) => {
        //barcodeData数组里所有money的和
        return prev + next.money
      }, 0)
    },
    inp1() {
      for (let b in this.barcodeData) {
        this.barcodeData[b].discount =
          (Number(this.barcodeData[b].onePrice) /
            Number(this.barcodeData[b].sellPrice)) *
          10
        this.barcodeData[b].money =
          this.barcodeData[b].onePrice * this.barcodeData[b].number
      }
      this.receivable = this.barcodeData.reduce((prev, next) => {
        //barcodeData数组里所有money的和
        return prev + next.money
      }, 0)
    },
    // inp2(){
    //   for(let c in this.barcodeData){
    //     this.barcodeData[c].money = this.barcodeData[c].onePrice * this.barcodeData[c].number
    //   }
    //   this.receivable = this.barcodeData.reduce((prev, next) => { //barcodeData数组里所有money的和
    //       return prev + next.money
    //     },0);
    // },

    rowClick(e) {
      console.log(e)
      console.log(e.receivable)
      // this.sellTime = e.sellTime
      // this.vip = e.vip
      // this.main = e.main
      // this.minor = e.minor
      // this.vipSellSequence = e.vipSellSequence
      // // this.isPaidOnePrice = a.isPaidOnePrice
      // this.receivable = e.receivable
      // this.preferential = e.preferential
      // this.exchange = e.exchange
      // this.payg = e.payg
      // this.discount = e.discount
      // this.onePrice = e.onePrice
      // this.balance = e.balance
    },
    changevip() {
      console.log(this.vip)
      //查询余额
      getmoney({ vip: this.vip }).then((res) => {
        console.log(res.data)
        this.balance = res.data.data.balance
        this.canExchange = res.data.data.canExchange
      })
      //查询折数
      getVip({ vip: this.vip }).then((res) => {
        console.log(res.data)
        for (let s of res.data.data) {
          this.discount = s.discount
        }
      })
    },

    closeNewClerk() {
      // this.isPaidOnePrice1 = false
      // this.isPaidOnePrice3 = false
      this.howMany = ''
      this.clean()
      this.title = ''
      this.title1 = ''
      this.Dis4 = ''
      this.jz = ''
      this.qr = ''
      this.lv = false
      this.xg = ''
      // this.this.isAffirm
      // this.barcodeData = []
      this.$emit('closeNew')
    },

    sibling(e) {
      let s = []
      let pp = e.parentNode.parentNode.children
      for (let j = 0; j < pp.length; j++) {
        let p = pp[j].children
        for (let i = 0, pl = p.length; i < pl; i++) {
          if (p[i] !== e) s.push(p[i])
        }
      }
      return s
    },
    // 输入货号后，颜色，尺码赋值
    csAssignment(str) {
      // 货号里提取色号，色号获取颜色
      // styleColor款色， 色尺colorSize
      let colorSize = str.slice(this.manufacturerBarCode.styleNumber).split('-')
      let tmpLen = 0
      if (this.manufacturerBarCode.styleColorSize) {
        // 型尺色

        if (this.manufacturerBarCode.styleColor) {
          // 款号与尺码之间有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -        MCC-A0001-7-001   ["", "7", "001"]
            this.knSize = colorSize[1]
            this.colorNo = colorSize[2]
          } else {
            // 色号与尺码之间没有 -        MCC-A0001-7001    ["", "7001"]
            tmpLen = colorSize[1].length
            this.knSize = colorSize[1].slice(
              0,
              tmpLen - this.manufacturerBarCode.colorNumber
            )
            this.colorNo = colorSize[1].slice(
              tmpLen - this.manufacturerBarCode.colorNumber
            )
          }
        } else {
          // 款号与尺码之间没有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -      MCC-A00017-001    ["7", "001"]
            this.knSize = colorSize[0]
            this.colorNo = colorSize[1]
          } else {
            // 色号与尺码之间没有 -     MCC-A00017001    ["7001"]
            tmpLen = colorSize[1].length
            this.knSize = colorSize[0].slice(
              0,
              tmpLen - this.manufacturerBarCode.colorNumber
            )
            this.colorNo = colorSize[0].slice(
              tmpLen - this.manufacturerBarCode.colorNumber
            )
          }
        }
      } else {
        // 型色尺

        if (this.manufacturerBarCode.styleColor) {
          // 款号与颜色之间有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -     MCC-A0001-001-7   ["", "001", "7"]
            this.colorNo = colorSize[1]
            this.knSize = colorSize[2]
          } else {
            // 色号与尺码之间没有 -    MCC-A0001-0017   ["", "0017"]
            tmpLen = colorSize[1].length
            this.colorNo = colorSize[1].slice(
              0,
              this.manufacturerBarCode.colorNumber
            )
            this.knSize = colorSize[1].slice(
              this.manufacturerBarCode.colorNumber
            )
          }
        } else {
          // 款号与颜色之间没有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -      MCC-A0001001-7      ["001", "7"]
            this.colorNo = colorSize[0]
            this.knSize = colorSize[1]
          } else {
            // 色号与尺码之间没有 -      MCC-A00010017     ["0017"]
            tmpLen = colorSize[1].length
            this.colorNo = colorSize[0].slice(
              0,
              this.manufacturerBarCode.colorNumber
            )
            this.knSize = colorSize[0].slice(
              this.manufacturerBarCode.colorNumber
            )
          }
        }
      }

      // 颜色
      getColorSeason({ no: this.colorNo, limit: 99999 }).then((res) => {
        // console.log(res)
        if (res.data.code == 200) {
          this.colorName = res.data.data[0].name
        }
      })

      // 尺码
      getSize({ kind: this.manufacturerBarCode.sizeKindId, limit: 99999 }).then(
        (res) => {
          // console.log(res)
          if (res.data.code == 200) {
            let list = res.data.data
            for (const i of list) {
              if (i.size == this.knSize) {
                this.knSizeList = [i]
                break
              }
            }
          }
        }
      )
    },

    //结账
    checkOut() {
      // this.$confirm(`单号${this.vipSellSequence}是否结账, 是否继续?', '提示`, {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // }).then(() => {
      CheckOut({ sellSequence: this.vipSellSequence }).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$message.success({ message: '结账成功' })
          this.$emit('closeNew')
          this.title1 = ''
          this.title = ''
          this.Dis4 = ''
          this.jz = ''
          this.qr = ''
          this.lv = ''
          this.xg = ''
          this.clean()
        } else {
          this.$message.console.error({ message: '结账失败' })
        }
      })
      // })
    },
    // 结账保存
    saveNew() {
      if (!this.sellTime) {
        this.$message.warning({ message: '销售日期不能为空' })
        return
      }
      getmoney({ vip: this.vip }).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          if (res.data.data != null) {
            this.canExchange = res.data.data.canExchange
          }
          // if(this.title == '新建'){
          if (
            Number(this.balance) + Number(this.payg) < this.receivable &&
            this.canExchange < this.receivable
          ) {
            this.$message.warning({
              message: '余额和可兑换额不足，请充值',
              offset: 400
            })
            return
          }

          // if(this.canExchange >= this.receivable){
          //   console.log(1)
          //   this.$confirm('兑换额足够，是否用兑换额付款, 是否继续?', '提示', {
          //   confirmButtonText: '确定',
          //   cancelButtonText: '余额付款',
          //   type: 'warning'
          // }).then(() => {

          this.Dis1 = false
          // this.receivable = this.canExchange

          // }).catch(()=>{ //取消 用余额付款
          //   console.log('取消')
          //   let obj3 = {
          //   sellTime:this.sellTime + ' 00:00:00',
          //   main:this.main,
          //   remark:this.remark,
          //   vip:this.vip,
          //   vipSellSequence:this.vipSellSequence,
          //   minor:this.minor,
          //   discount:this.discount,
          //   isPaidOnePrice:this.isPaidOnePrice == false ? 0 : 1,
          //   onePrice:this.onePrice,
          //   receivable:this.receivable,
          //   preferential:this.preferential,
          //   exchange:this.exchange,
          //   payg:this.payg,
          //   BigDecimal:this.BigDecimal
          // }
          // console.log(obj3)
          // postShop(obj3).then(res=>{
          //   console.log(res.data)
          //   if(res.data.code = 200){

          //     if(this.exchange == '' && this.payg == '' && this.BigDecimal == ''){
          //       this.$confirm('兑换和收现,转账都为空 是否结账, 是否继续?', '提示', {
          //         confirmButtonText: '确定',
          //         cancelButtonText: '取消',
          //         type: 'warning'
          //       }).then(() => {this.checkOut()});
          //     }else{
          //       this.checkOut()
          //     }

          //   }else{this.$message.error({message:'保存失败'})}
          // })
          // });

          // }else{
          let obj2 = {
            sellTime: this.sellTime + ' 00:00:00',
            main: this.main,
            remark: this.remark,
            vip: this.vip,
            vipSellSequence: this.vipSellSequence,
            minor: this.minor,
            discount: this.discount,
            isPaidOnePrice: this.isPaidOnePrice == false ? 0 : 1,
            onePrice: this.onePrice,
            receivable: this.receivable,
            preferential: this.preferential,
            exchange: this.exchange == 0 ? '' : this.exchange,
            payg: this.payg == 0 ? '' : this.payg,
            BigDecimal: this.BigDecimal
          }
          console.log(obj2)
          postShop(obj2).then((res) => {
            console.log(res.data)
            if ((res.data.code = 200)) {
              if (
                this.exchange == '' &&
                this.payg == '' &&
                this.BigDecimal == ''
              ) {
                this.$confirm(
                  '兑换和收现,转账都为空 是否结账, 是否继续?',
                  '提示',
                  {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                  }
                ).then(() => {
                  this.checkOut()
                })
              } else {
                let obj = {
                  sellTime: this.sellTime + ' 00:00:00',
                  main: this.main,
                  remark: this.remark,
                  vip: this.vip,
                  vipSellSequence: this.vipSellSequence,
                  minor: this.minor,
                  discount: this.discount,
                  isPaidOnePrice: this.isPaidOnePrice == false ? 0 : 1,
                  onePrice: this.onePrice,
                  receivable: this.receivable,
                  preferential: this.preferential,
                  exchange: this.exchange == 0 ? '' : this.exchange,
                  payg: this.payg == 0 ? '' : this.payg,
                  BigDecimal: 0
                }
                console.log(obj)
                postShop(obj).then((res) => {
                  console.log(res.data)
                  if ((res.data.code = 200)) {
                    // this.clean()
                    // this.exchange = this.receivable
                    this.checkOut()
                    this.Dis1 = true
                    this.howMany = ''
                  } else {
                    this.$message.error({ message: '保存失败' })
                  }
                })
              }
            } else {
              this.$message.error({ message: '保存失败' })
            }
          })
          // }

          // }
          // // if(this.title == '编辑'){
          //   for(let c in this.barcodeData){
          //   this.barcodeData[c]['sellTime'] = this.sellTime.slice(0,10) + 'T00:00:00',
          //   this.barcodeData[c]['main'] = this.main,
          //   this.barcodeData[c]['vip'] = this.vip,
          //   this.barcodeData[c]['vipSellSequence'] = this.vipSellSequence,
          //   this.barcodeData[c]['minor'] = this.minor,
          //   this.barcodeData[c]['customerSellSequence'] = this.customerSellSequence,
          //   // this.barcodeData[c]['discount'] = this.discount,
          //   this.barcodeData[c]['isPaidOnePrice'] = this.isPaidOnePrice == false ? 0 : 1,
          //   // this.barcodeData[c]['onePrice'] = this.onePrice,
          //   this.barcodeData[c]['receivable'] = this.receivable,
          //   this.barcodeData[c]['preferential'] = this.preferential,
          //   this.barcodeData[c]['exchange'] = this.exchange,
          //   this.barcodeData[c]['payg'] = this.payg
          //   this.barcodeData[c]['BigDecimal'] = this.BigDecimal
          // }
          //   console.log(JSON.stringify(this.barcodeData))
          //   putShop(JSON.stringify(this.barcodeData)).then(res=>{
          //     console.log(res.data)
          //     if(res.data.code == 200){
          //       // this.$message.success({message:'保存成功'})
          //       if(this.exchange == '' && this.payg == '' && this.BigDecimal == ''){
          //           this.$confirm(`兑换和收现,转账都为空 是否结账, 是否继续?', '提示`, {
          //             confirmButtonText: '确定',
          //             cancelButtonText: '取消',
          //             type: 'warning'
          //           }).then(() => {this.checkOut()});
          //         }else{
          //           this.checkOut()
          //         }

          //     }else{this.$message.error({message:'保存失败'})}
          //   })
          // // }
        }
      })
    },
    leave() {
      this.receivable =
        Number(localStorage.getItem('money')) -
        Number(this.preferential == '' ? 0 : this.preferential)
    },
    keepGoing() {
      if (this.vip == '') {
        this.$message.warning({ message: 'vip不能为空' })
        return
      }
      if (this.discount == '' && this.onePrice == '') {
        this.$message.warning({ message: '折数或实收单价需选填一个' })
        return
      }
      if (this.main == '' || this.minor == '') {
        this.$message.warning({ message: '主推，次推不能为空' })
        return
      }
      if (this.barcode == '') {
        this.$message.warning({ message: '请输入货号' })
        return
      }
      this.continueInput()

      // let obj = {
      //         sellTime:this.sellTime.slice(0,10) + 'T00:00:00',
      //         vip:this.vip,
      //         main:this.main,
      //         minor:this.minor,
      //         vipSellSequence:this.vipSellSequence,
      //         discount:this.discount,
      //         isPaidOnePrice:this.isPaidOnePrice == false ? 0 : 1,
      //         onePrice:this.onePrice,
      //         receivable:this.receivable,
      //         preferential:this.preferential,
      //         exchange:this.exchange,
      //         payg:this.payg,
      //         BigDecimal:this.BigDecimal,
      //         balance:this.balance,
      //         number:1,
      //         kindsNumber:this.barcode,
      //         customerSellSequence:this.customerSellSequence
      //       }
      //       let x = false
      //       console.log(JSON.stringify([obj]))
      //       keepPostShop(JSON.stringify([obj])).then(res=>{
      //         console.log(res.data)

      //         if(res.data.code == 200){
      //           for(let u of res.data.data){
      //             this.vipSellSequence = u.vipSellSequence
      //             this.customerSellSequence = u.customerSellSequence
      //             console.log(this.vipSellSequence)
      //             console.log(this.customerSellSequence)
      //           }
      //           this.Dis = false
      //           if(JSON.parse(JSON.stringify(this.barcodeData)) == ''){
      //               this.barcodeData = res.data.data
      //             }else{
      //               console.log(5,res.data.data[0].kindsNumber)
      //               for(let i=0;i<this.barcodeData.length;i++){
      //                 console.log(this.barcodeData[i].kindsNumber)
      //                 if(this.barcodeData[i].kindsNumber == res.data.data[0].kindsNumber){
      //                   this.barcodeData[i] = res.data.data[0]
      //                   x = false  //let x 赋值false 如果数组表里有相同就覆盖 没有就添加
      //                 }else{
      //                   x = true
      //                 }
      //               }
      //               console.log(x)
      //               if(x == true){
      //                 this.barcodeData.push(res.data.data[0])
      //               }

      //             }

      //           this.receivable = this.barcodeData.reduce((prev, next) => { //barcodeData数组里所有money的和
      //             return prev + next.money
      //           },0);
      //           localStorage.setItem('money',this.receivable)
      //           this.leave()
      //         }

      //       });
    },
    // 继续录入
    continueInput() {
      getTime({ customerNo: this.customerNo }).then((res) => {
        var time
        console.log(res.data)
        time = Number(res.data.data.slice(0, 10).replace(/\-|-/g, ''))

        if (Number(this.sellTime.slice(0, 10).replace(/\-|-/g, '')) < time) {
          var time1 =
            String(time).slice(0, 4) +
            '年' +
            String(time).slice(4, 6) +
            '月' +
            String(time).slice(6, 8) +
            '日'
          this.$message.warning({
            message: `时间不合法，不能早于${time1} `,
            offset: 400
          })
          return
        } else {
          this.commodityName = ''
          this.sellingPrice = ''

          // 之前输入货号录入1条
          if (JSON.stringify(this.tmpData) != '{}') {
            // console.log(this.tmpData)
            // console.log(this.barcodeData.length)
            if (!this.barcodeData.length) {
              this.barcodeData.push(this.tmpData)
              this.tmpData = {}
            } else {
              for (const i of this.barcodeData) {
                if (i.kindsNumber == this.tmpData.kindsNumber) {
                  i.number = Number(i.number) + Number(this.tmpData.number)
                  this.tmpData = {}
                  // this.$forceUpdate()
                  return
                }
              }
              this.barcodeData.push(this.tmpData)
              this.tmpData = {}
            }
            this.barcode = ''
            return
          }

          // 之前输入款号录入多条
          // console.log(this.codeData)
          let knList = []
          this.codeData.forEach((e) => {
            let c = e.colorNo
            this.sizeList.forEach((f) => {
              if (this.manufacturerBarCode.styleColorSize) {
                // 型尺色

                if (this.manufacturerBarCode.styleColor) {
                  // 款号与尺码之间有 -

                  if (this.manufacturerBarCode.colorSize) {
                    // 色号与尺码之间有 -
                    knList.push({
                      kindsNumber: `${this.header}-${f}-${c}`,
                      number: e[f]
                    })
                  } else {
                    // 色号与尺码之间没有 -
                    knList.push({
                      kindsNumber: `${this.header}-${f}${c}`,
                      number: e[f]
                    })
                  }
                } else {
                  // 款号与尺码之间没有 -

                  if (this.manufacturerBarCode.colorSize) {
                    // 色号与尺码之间有 -
                    knList.push({
                      kindsNumber: `${this.header}${f}-${c}`,
                      number: e[f]
                    })
                  } else {
                    // 色号与尺码之间没有 -
                    knList.push({
                      kindsNumber: `${this.header}${f}${c}`,
                      number: e[f]
                    })
                  }
                }
              } else {
                // 型色尺

                if (this.manufacturerBarCode.styleColor) {
                  // 款号与颜色之间有 -

                  if (this.manufacturerBarCode.colorSize) {
                    // 色号与尺码之间有 -
                    knList.push({
                      kindsNumber: `${this.header}-${c}-${f}`,
                      number: e[f]
                    })
                  } else {
                    // 色号与尺码之间没有 -
                    knList.push({
                      kindsNumber: `${this.header}-${c}${f}`,
                      number: e[f]
                    })
                  }
                } else {
                  // 款号与颜色之间没有 -

                  if (this.manufacturerBarCode.colorSize) {
                    // 色号与尺码之间有 -
                    knList.push({
                      kindsNumber: `${this.header}${c}-${f}`,
                      number: e[f]
                    })
                  } else {
                    // 色号与尺码之间没有 -
                    knList.push({
                      kindsNumber: `${this.header}${c}${f}`,
                      number: e[f]
                    })
                  }
                }
              }
            })
          })
          console.log(knList)
          console.log(this.tmpBarcodeData)

          for (const k of knList) {
            for (const l of this.tmpBarcodeData) {
              if (k.kindsNumber == l.kindsNumber) {
                l.number = k.number
              }
            }
          }
          console.log(this.tmpBarcodeData)

          let isExist = 0
          this.barcodeData1 = []
          for (const g of this.tmpBarcodeData) {
            // if (!Number(g.number)) continue
            if (g.number != '') {
              console.log(g)
              this.barcodeData1.push(g)
            }
            // for (const h of this.barcodeData1) {
            //   if (h.kindsNumber == g.kindsNumber) {
            //     h.number = Number(h.number) + Number(g.number)
            //     isExist = 0
            //     break
            //   }
            //   isExist = 1
            // }
            // if (isExist) {
            //   this.barcodeData1.push(g)
            // }
            // console.log(this.barcodeData1)
            var sendList = []
            this.barcodeData1.forEach((e) => {
              sendList.push({ kindsNumber: e.kindsNumber, number: e.number })
            })

            // this.$forceUpdate()
          }
          console.log(this.onePrice)
          if (this.title == '新建') {
            console.log(this.receivable)
            this.$nextTick(() => {
              for (let p in sendList) {
                sendList[p]['sellTime'] =
                  this.sellTime.slice(0, 10) + 'T00:00:00'
                sendList[p]['vip'] = this.vip
                sendList[p]['main'] = this.main
                sendList[p]['remark'] = this.remark
                sendList[p]['minor'] = this.minor
                sendList[p]['vipSellSequence'] = this.vipSellSequence
                sendList[p]['discount'] = this.discount
                if (this.onePrice != '') {
                  sendList[p]['onePrice'] = this.onePrice
                  // sendList[p]['discount'] = Number(sendList[p].onePrice) / Number(sendList[p].sellPrice) * 10
                }

                sendList[p]['isPaidOnePrice'] =
                  this.isPaidOnePrice == false ? 0 : 1
                sendList[p]['receivable'] = this.receivable
                sendList[p]['preferential'] = this.preferential
                sendList[p]['exchange'] = this.exchange
                sendList[p]['payg'] = this.payg
                sendList[p]['BigDecimal'] = this.BigDecimal
                sendList[p]['balance'] = this.balance
                sendList[p]['customerSellSequence'] = this.customerSellSequence
              }
              console.log(sendList)
              keepPostShop(JSON.stringify(sendList)).then((res) => {
                console.log(res.data)
                if (res.data.code == 200) {
                  this.jz = true
                  this.qr = false
                  this.xg = true
                  this.Dis4 = true
                  this.lv = false
                  for (let u of res.data.data) {
                    this.vipSellSequence = u.vipSellSequence
                    this.customerSellSequence = u.customerSellSequence
                  }
                  this.barcodeData = res.data.data
                  this.$emit('save', this.barcodeData)
                  this.Dis = false
                  console.log(this.barcodeData)
                  this.receivable = this.barcodeData.reduce((prev, next) => {
                    //barcodeData数组里所有money的和
                    return prev + next.money
                  }, 0)
                  this.howMany = this.barcodeData.reduce((prev, next) => {
                    return prev + next.number
                  }, 0)
                  localStorage.setItem('money', this.receivable)
                  this.leave()
                }
              })
            })
          }
          //补单
          if (this.title == '补单') {
            console.log('补单')
            this.$nextTick(() => {
              for (let p in sendList) {
                sendList[p]['sellTime'] =
                  this.sellTime.slice(0, 10) + 'T00:00:00'
                sendList[p]['vip'] = this.vip
                sendList[p]['main'] = this.main
                sendList[p]['remark'] = this.remark
                sendList[p]['minor'] = this.minor
                sendList[p]['vipSellSequence'] = this.vipSellSequence
                sendList[p]['discount'] = this.discount
                if (this.onePrice != '') {
                  sendList[p]['onePrice'] = this.onePrice
                  // sendList[p]['discount'] = Number(sendList[p].onePrice) / Number(sendList[p].sellPrice) * 10
                }
                sendList[p]['isPaidOnePrice'] =
                  this.isPaidOnePrice == false ? 0 : 1
                sendList[p]['receivable'] = this.receivable
                sendList[p]['preferential'] = this.preferential
                sendList[p]['exchange'] = this.exchange
                sendList[p]['payg'] = this.payg
                sendList[p]['BigDecimal'] = this.BigDecimal
                sendList[p]['balance'] = this.balance
                sendList[p]['customerSellSequence'] = this.customerSellSequence
                sendList[p]['isMakeUp'] = 1
              }
              console.log(sendList)
              keepPostShop(JSON.stringify(sendList)).then((res) => {
                console.log(res.data)
                if (res.data.code == 200) {
                  this.$message.success({ message: '补单成功', offset: 400 })
                  for (let u of res.data.data) {
                    this.vipSellSequence = u.vipSellSequence
                    this.customerSellSequence = u.customerSellSequence
                  }
                  this.barcodeData = res.data.data
                  this.$emit('save', this.barcodeData)
                  this.Dis = false
                  console.log(this.barcodeData)
                  this.receivable = this.barcodeData.reduce((prev, next) => {
                    //barcodeData数组里所有money的和
                    return prev + next.money
                  }, 0)
                  this.howMany = this.barcodeData.reduce((prev, next) => {
                    return prev + next.number
                  }, 0)
                  localStorage.setItem('money', this.receivable)
                  this.leave()
                } else {
                  this.$message.error({ message: '补单失败', offset: 400 })
                }
              })
            })
          }
          this.howMany = this.barcodeData.reduce((prev, next) => {
            return prev + next.number
          }, 0)
          this.barcode = ''
          this.header = ''
          this.codeData = []
        }
      })
    },

    // 扫描/输入货号或款号
    barcodeEnter(e) {
      if (this.vip == '') {
        this.$message.warning({ message: 'vip不能为空' })
        return
      }
      if (this.discount == '' && this.onePrice == '') {
        this.$message.warning({ message: '折数或实收单价需选填一个' })
        return
      }
      if (this.main == '' || this.minor == '') {
        this.$message.warning({ message: '主推，次推不能为空' })
        return
      }
      if (this.barcode) {
        if (this.isBarcode) {
          // 扫描货号
          // getKindsNumberList({kindsNumberStr: this.barcode}).then(res => {
          //   console.log(res)
          //   if (res.data.code == 200) {
          //     this.commodityName = res.data.data.data[0].commodityName
          //     this.sellingPrice = res.data.data.data[0].sellingPrice
          //     this.tmpData = res.data.data.data[0]
          //     this.tmpData.number = this.scanNum
          //     this.tmpData.onePrice = this.tmpData.discount / 10 * this.tmpData.sellingPrice
          //     this.$refs.barcodeInput.focus()
          //     // this.continueInput()
          //   }
          // })
          if (this.title == '新建') {
            var obj4 = {
              sellTime: this.sellTime.slice(0, 10) + 'T00:00:00',
              vip: this.vip,
              main: this.main,
              remark: this.remark,
              minor: this.minor,
              vipSellSequence: this.vipSellSequence,
              discount: this.discount,
              isPaidOnePrice: this.isPaidOnePrice == false ? 0 : 1,
              receivable: this.receivable,
              preferential: this.preferential,
              exchange: this.exchange,
              payg: this.payg,
              BigDecimal: this.BigDecimal,
              onePrice: this.onePrice,
              balance: this.balance,
              number: 1,
              kindsNumber: this.barcode,
              customerSellSequence: this.customerSellSequence
            }
          }
          if (this.title == '补单') {
            console.log('补单')
            var obj4 = {
              sellTime: this.sellTime.slice(0, 10) + 'T00:00:00',
              vip: this.vip,
              main: this.main,
              remark: this.remark,
              minor: this.minor,
              vipSellSequence: this.vipSellSequence,
              discount: this.discount,
              receivable: this.receivable,
              preferential: this.preferential,
              isPaidOnePrice: this.isPaidOnePrice == false ? 0 : 1,
              onePrice: this.onePrice,
              exchange: this.exchange,
              payg: this.payg,
              BigDecimal: this.BigDecimal,
              balance: this.balance,
              number: 1,
              kindsNumber: this.barcode,
              customerSellSequence: this.customerSellSequence,
              isMakeUp: 1
            }
          }
          console.log(obj4)

          let x = false
          console.log(JSON.stringify([obj4]))
          keepPostShop(JSON.stringify([obj4])).then((res) => {
            console.log(res.data)
            console.log(JSON.parse(JSON.stringify(this.barcodeData)))
            if (res.data.code == 200) {
              for (let u of res.data.data) {
                this.vipSellSequence = u.vipSellSequence
                this.customerSellSequence = u.customerSellSequence
              }
              this.Dis = false
              // if(JSON.parse(JSON.stringify(this.barcodeData)) == ''){
              //     this.barcodeData = res.data.data
              //   }else{
              //     for(let i=0;i<this.barcodeData.length;i++){
              //       if(this.barcodeData[i].kindsNumber == res.data.data[0].kindsNumber){
              //         this.barcodeData[i] = res.data.data[0]
              //         x = false  //let x 赋值false 如果数组表里有相同就覆盖 没有就添加
              //       }else{
              //         x = true
              //       }
              //     }
              //     // this.barcodeData.push(res.data.data[0])
              //     console.log(x)
              //     if(x == true){
              //       this.barcodeData.push(res.data.data[0])
              //     }

              //   }
              this.barcodeData = res.data.data
              var arr1 = []
              this.barcodeData.forEach((e) => {
                arr1.push(e.money)
              })
              var sum = 0
              arr1.forEach((item) => {
                sum = sum + item
              })
              this.receivable = sum
              localStorage.setItem('money', this.receivable)
              this.leave()
              this.howMany = this.barcodeData.reduce((prev, next) => {
                return prev + next.number
              }, 0)
              this.barcode = ''
              document.getElementById('input').focus()
            }

            // var sum = 0
            // for(let s=0;s<this.barcodeData.length;s++){
            //   sum += s.money
            //   this.receivable = sum
            // }
          })
        } else {
          console.log(2)
          // 手输款号
          getKindsNumberList({ kindsNumberStr: this.barcode }).then((res) => {
            this.XHList = res.data.data.data
            console.log(this.XHList)
            if (res.data.data.data.length) {
              this.header = res.data.data.data[0].styleNumber
              this.$emit('inpNumChange')
              // 品牌公司查条码规律详情
              getBarCode({
                company: res.data.data.data[0].brandedCompany
              }).then((res) => {
                // console.log(res)
                this.manufacturerBarCode = res.data.data[0]
              })
              // console.log(this.manufacturerBarCode)
              // 输入款号显示中间表和尺码信息   ZZZ-AAS
              res.data.data.data.sort((a, b) => {
                return a.relevanceSize.localeCompare(b.relevanceSize)
              })
              let tmp = res.data.data.data
              this.tmpBarcodeData = tmp
              // console.log(tmp)

              // 中间表  尺码表头
              this.sizeList = [tmp[0].size]
              let isExistSize = 0
              for (const i of tmp) {
                for (const j of this.sizeList) {
                  if (j == i.size) {
                    isExistSize = 0
                    break
                  }
                  isExistSize = 1
                }
                if (isExistSize) {
                  this.sizeList.push(i.size)
                  console.log(this.sizeList)
                }
              }

              // 中间表
              let tmpCodeData = [
                { colorNo: tmp[0].colorNo, colorName: tmp[0].colorName }
              ]
              let isExistColor = 0
              for (const i of tmp) {
                for (const j of tmpCodeData) {
                  if (j.colorName == i.colorName) {
                    isExistColor = 0
                    break
                  }
                  isExistColor = 1
                }
                if (isExistColor) {
                  tmpCodeData.push({
                    colorNo: i.colorNo,
                    colorName: i.colorName
                  })
                }
              }
              tmpCodeData.forEach((e) => {
                this.sizeList.forEach((f) => {
                  e[f] = ''
                })
              })
              this.codeData = tmpCodeData
              let codeTable = document.getElementById('codeTable')
              let inputs = codeTable.getElementsByTagName('input')
              // console.log(inputs)
              let int = setTimeout(() => {
                clearTimeout(int)
                inputs[0].focus()
                inputs[inputs.length - 1].onkeyup = (e) => {
                  if (window.event.keyCode == 13) {
                    this.continueInput()
                    // inputs[inputs.length - 1].onkeyup = () => {}
                  }
                }
              }, 500)
            } else {
              this.$message('此货号/款号无数据')
              // this.$refs.barcodeInput.focus()
            }
          })
        }
      }
    },

    closePopup() {
      this.showPopup = 'none'
      this.scanNum = this.beforeScanNum
    },

    //  输入回车/失去焦点统计
    //  index 行索引
    //  result 输入内容
    handleClick(e, { index, key, result }) {
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
      // let r = /^\+?[1-9][0-9]*$/
      // if (result != 0) {
      //   result = result.replace(/\b(0+)/gi,"")
      // }
      // if (!r.test(result) && result) {
      //   this.$alert('数量请输入正整数', '', {
      //     confirmButtonText: '确定'
      //   })
      //   this.codeData[index][key] = 0
      //   return
      // }
      this.codeData[index][key] = result
    },
    cellClick(row, column, cell, event) {
      cell.classList.add('activeCell')
      let s = this.sibling(cell)
      // console.log(s)
      s.forEach((e) => {
        e.classList.remove('activeCell')
      })
    },
    inpEnter(e) {
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
    },
    clean() {
      this.customerSellSequence = ''
      this.barcode = ''
      this.vip = ''
      this.main = ''
      this.remark = ''
      this.isAffirm = ''
      this.minor = ''
      this.vipSellSequence = ''
      this.discount = ''
      this.isPaidOnePrice = false
      this.onePrice = ''
      this.receivable = ''
      this.preferential = ''
      this.exchange = ''
      this.payg = ''
      this.BigDecimal = ''
      this.balance = ''
      this.canExchange = ''
      this.codeData = []
      this.barcodeData = []
    }
  },
  mounted() {
    if (this.title != '新建') {
      this.fillData()
      this.clerkListChange()
    }
    this.title1Change()
    this.titleChange()
    let _this = this
    document.onkeydown = function (event) {
      let e = event || window.event || arguments.callee.caller.arguments[0]
      if (e && e.keyCode == 118) {
        // 按 F7
        // console.log('an f7')
        if (_this.showPopup == 'none') {
          _this.beforeScanNum = _this.scanNum
          _this.showPopup = 'block'
        } else {
          _this.showPopup = 'none'
        }
      }
    }
  }
}
</script>

<style scoped>
/* 新建资料 */
.mask {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.3;
  z-index: 9;
}
.new_vs {
  position: fixed;
  top: 7%;
  left: 50%;
  transform: translateX(-50%);
  width: 1200px;
  max-height: 800px;
  z-index: 99;
  background-color: white;
  overflow: auto;
}
.new_vs .vs-top {
  height: 40px;
  background-color: #f8f8f8;
  margin-bottom: 10px;
}
.new_vs .vs-top p {
  float: left;
  line-height: 40px;
  padding-left: 20px;
  font-weight: 700;
}
.new_vs .vs-top i {
  float: right;
  line-height: 40px;
  padding: 0 16px;
}

.new_vs input {
  height: 30px;
  border: solid 1px #dcdfe6;
  border-radius: 5px;
  margin-left: 10px;
}
.new_vs input:focus {
  outline: none;
  border: solid 1px #409eff;
}

.vs-info {
  padding: 0 20px;
}
.vs-info .info {
  height: 30px;
  margin-bottom: 10px;
}
.vs-info p {
  display: inline-block;
  width: 100px;
  text-align: right;
  margin-right: 15px;
}
.colorBox,
.infoBox {
  display: inline;
}

.enterBarcode {
  display: flex;
  height: 60px;
  background-color: #f2f2f2;
  margin: 15px 0;
}

.vs-btn {
  float: right;
  margin: 15px 15px;
}

.popup {
  width: 400px;
  height: 200px;
  border: 2px solid #f4f4f4;
  box-shadow: 0 2px 2px 2px #dbdbdb;
  z-index: 999;
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -100px 0 0 -200px;
  background: white;
  display: block;
}
.popup_t {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 40px;
  background: rgb(244, 244, 244);
  padding: 8px 15px;
}
.popup_t p {
  font-weight: 700;
}
.popup_c {
  padding: 8px 15px;
}
.popup_button {
  margin: 5px 0 0 0;
  width: 94%;
  height: 30px;
  padding: 0 10px;
  border: 2px solid #f4f4f4;
  border-radius: 3px;
}
.popup_b {
  margin: 10px 0 0 0;
  padding-left: 230px;
}
</style>

<style>
.new_vs .info .el-input,
.new_vs .info .el-select {
  width: 160px;
}
.new_vs .el-input__inner {
  height: 30px !important;
}
.new_vs .el-input__icon {
  line-height: 30px !important;
}
.vs-info .barcode .el-switch {
  margin: 0 !important;
}

.new_vs .enterBarcode .el-input {
  width: 486px;
  margin: 14px 17px;
}

.new_vs .colorBox .el-input {
  width: 60px;
  margin-right: 10px;
}
.new_vs .colorBox .el-input--suffix {
  width: 90px;
}

.new_vs input:focus {
  outline: none;
  border: buildlid 1px #409eff;
}
</style>
